Linux zip命令:压缩文件或目录

您所在的位置:网站首页 linux zip压缩不带路径 Linux zip命令:压缩文件或目录

Linux zip命令:压缩文件或目录

2024-02-01 15:27| 来源: 网络整理| 查看: 265

我们经常会在 Windows 系统上使用 “.zip”格式压缩文件,其实“.zip”格式文件是 Windows 和 Linux 系统都通用的压缩文件类型,属于几种主流的压缩格式(zip、rar等)之一,是一种相当简单的分别压缩每个文件的存储格式,本节要讲的 zip 命令,类似于 Windows 系统中的 winzip 压缩程序,其基本格式如下:

[root@localhost ~]#zip [选项] 压缩包名 源文件或源目录列表

注意,zip 压缩命令需要手工指定压缩之后的压缩包名,注意写清楚扩展名,以便解压缩时使用。

下面给大家举几个例子。

【例 1】zip 命令的基本使用。

[root@localhost ~]# zip ana.zip anaconda-ks.cfg adding: anaconda-ks.cfg (deflated 37%) #压缩 [root@localhost ~]# ll ana.zip -rw-r--r-- 1 root root 935 6月 1716:00 ana.zip #压缩文件生成

不仅如此,所有的压缩命令都可以同时压缩多个文件,例如:

[root@localhost ~]# zip test.zip install.log install.log.syslog adding: install.log (deflated 72%) adding: install.log.syslog (deflated 85%) #同时压缩多个文件到test.zip压缩包中 [root@localhost ~]#ll test.zip -rw-r--r-- 1 root root 8368 6月 1716:03 test.zip #压缩文件生成

【例 2】使用 zip 命令压缩目录,需要使用“-r”选项,例如:

[root@localhost ~]# mkdir dir1 #建立测试目录 [root@localhost ~]# zip -r dir1.zip dir1 adding: dir1/(stored 0%) #压缩目录 [root@localhost ~]# ls -dl dir1.zip -rw-r--r-- 1 root root 160 6月 1716:22 dir1.zip #压缩文件生成



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3